package com.wenwei.sharebox.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.MyLocationStyle;
import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.ActionSheetDialog;
import com.orhanobut.logger.Logger;
import com.wenwei.sharebox.R;
import com.wenwei.sharebox.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/11.
 */
public class MapLocationActivity extends BaseActivity {

    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.map_view)
    MapView mapView;
    @Bind(R.id.bottom_layout)
    RelativeLayout locationRl;

    MyLocationStyle myLocationStyle;

    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_map_location;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        mapView.onCreate(savedInstanceState);
    }

    //    30.5680255130,104.0647745132
    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("商品定位");
        AMap aMap = mapView.getMap();
        aMap.setMapType(AMap.MAP_TYPE_NORMAL);

        myLocationStyle = new MyLocationStyle();
        myLocationStyle.interval(2000);
        aMap.setMyLocationStyle(myLocationStyle);
        aMap.setMyLocationEnabled(true);
        aMap.moveCamera(CameraUpdateFactory.zoomTo(13));
        myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW);//定位一次，且将视角移动到地图中心点。
        myLocationStyle.showMyLocation(true);
    }


    private void showDialog() {
        ActionSheetDialog dialog = new ActionSheetDialog(mContext, new String[]{"", ""}, null);
        dialog.title("选择导航方式");
        dialog.show();
        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> parent, View view, int position, long id) {
                Logger.d("当前位置：" + position);
            }
        });
    }

    @OnClick({R.id.base_back, R.id.bottom_layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finish();
                break;
            case R.id.bottom_layout:
                showDialog();
                break;
        }
    }
}
